[cffi] Fix FFI.new's init arg is now Any.#15683
Conversation
This comment has been minimized.
This comment has been minimized.
|
If left undeclared it's equivalent to Any, so adding Any doesn't give more information. |
|
It does make a difference for BasedPyright at least. I verified, by applying the change locally in the sitepackages. BasedPyright seems to distinguish between being explicit about there not being type information and just omitting it. My guess, to prevent developers from forgetting to annotate functions. In the later case BasedPyright classifies the type as "Unknown" rather than any. |
|
I understand the type checker behavior here, but that error exists so that you're alerted about calling functions where the type checker doesn't know the allowed argument type. Blindly adding Any makes the error go away but doesn't fix the underlying problem: we still don't know what argument types are allowed. That said, perhaps the "true" type really can't be expressed in the type system here, in which case Any is correct. But then our policy asks that we add a comment to each Any explaining why we need it. |
Same as _cffi_backend.pyi's declaration
|
Added a comment motivating the Any. There might also be union which is narrow than Not sure this is better though. Type checking will always be wanting in this situation, because the allowed type depends on the value of cdecl which is only known at runtime. The decision made in Followed your advice and added a comment to the declaration. |
This comment has been minimized.
This comment has been minimized.
|
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
- pandas/core/computation/ops.py:328: error: Need type annotation for "_binary_ops_dict" (hint: "_binary_ops_dict: dict[<type>, <type>] = ...") [var-annotated]
|
Same as _cffi_backend.pyi's declaration. See:
typeshed/stubs/cffi/_cffi_backend.pyi
Line 196 in e4d32e0
Without it basedpyright complains the type of new is partially unknown.